import global from './config.js'
import request from './request.js'
import tool from './tool.js'
import mixin from './mixin.js'
import update from './update.js'
import store from "./store"

update(global.baseUrl)
const install = Vue => {
	Vue.mixin(mixin) //全局混入
	Vue.prototype.$store = store //全局配置  接口地址等
	Vue.prototype.$global = global //全局配置  接口地址等
	Vue.prototype.$baseUrl = global.baseUrl //接口地址
	Vue.prototype.$request = request //请求逻辑
	Vue.prototype.$tool = tool //工具栏
	Vue.prototype.$navBack = tool.navBack //工具栏
	Vue.prototype.$msg = tool.msg //提示
	Vue.prototype.$showModal = tool.showModal //二次确认框
	Vue.prototype.$refresh = tool.refresh //刷新页面 当前页面onLoad
	Vue.prototype.$log = (e) => console.log(e) //常用于页面视图层log 点击回调参数等

	Vue.prototype.$paths = (paths, num) => { //多图单图处理拼接链接
		if (!paths) return paths || ''
		if (!paths.length) return paths || ''
		let arr = paths.toString().split(',')
		arr = arr.map(e => global.baseUrl + e)
		if (num == 1) return arr[0]
		return arr
	}

	// Vue.prototype.$getCache = (field) => { //读取缓存
	// 	return getApp()?.globalData?. [field] || uni.getStorageSync(field) || ''
	// }
	// Vue.prototype.$setCache = (field, data) => { //设置缓存
	// 	getApp().globalData[field] = data
	// 	uni.setStorageSync(field, data)
	// }

	Vue.prototype.$getCache = (field) => { //读取缓存
		return store.state[field] || uni.getStorageSync(field) || ''
	}

	Vue.prototype.$setCache = (field, data) => { //设置缓存
		store.commit('setData', [field, data])
	}

	Vue.prototype.$goChat = (params) => {
		uni.$u.route('/pages/chat/chat', params)
	}

	Vue.prototype.$goDemo = (item) => {
		uni.$u.route('/pages/index/demo/detail', {
			service_id: item.service_id || item.id,
			om_service_id: item.om_service_id||'',
			organ_id: item.organ_id || '',
			hospital_id: item.hospital_id || '',
			master_id: item.master_id || '',
			type:item.type||'',
		})
	}

	Vue.prototype.$text = (fidle) => {
		let obj = {
			identity: {

			}
		}
		return obj[fidle]
	}

	Vue.prototype.$list = (fidle) => {
		let rules = {
			name: [{
				required: true,
				message: '请输入名称',
				// blur和change事件触发检验
				trigger: ['blur', 'change'],
			}, ],
			credit_code: [{
				required: true,
				message: '请输入代码',
				// blur和change事件触发检验
				trigger: ['blur', 'change'],
			}, ],
			legal_person: [{
				required: true,
				message: '请输入代表人',
				// blur和change事件触发检验
				trigger: ['blur', 'change'],
			}, ],
			card_no: [{
				required: true,
				message: '请输入身份证号',
				// blur和change事件触发检验
				trigger: ['blur', 'change'],
			}, {
				// 自定义验证函数，见上说明
				validator: (rule, value, callback) => {
					console.log();
					// this.$u.test.mobile()就是返回true或者false的
					return uni.$u.test.idCard(value);
				},
				message: '身份证号不正确',
				// 触发器可以同时用blur和change
				trigger: ['change', 'blur'],
			}],
			card_pros: [{
				required: true,
				message: '请上传身份证',
				// blur和change事件触发检验
				trigger: ['blur', 'change'],
			}, ],
			card_cons: [{
				required: true,
				message: '请上传身份证',
				// blur和change事件触发检验
				trigger: ['blur', 'change'],
			}, ],
			mobile: [{
					required: true,
					message: '请输入手机号',
					// blur和change事件触发检验
					trigger: ['blur', 'change'],
				},
				{
					// 自定义验证函数，见上说明
					validator: (rule, value, callback) => {
						console.log();
						// this.$u.test.mobile()就是返回true或者false的
						return uni.$u.test.mobile(value);
					},
					message: '手机号码不正确',
					// 触发器可以同时用blur和change
					trigger: ['change', 'blur'],
				}
			],
			phone: [{
					required: true,
					message: '请输入手机号',
					// blur和change事件触发检验
					trigger: ['blur', 'change'],
				},
				{
					// 自定义验证函数，见上说明
					validator: (rule, value, callback) => {
						console.log();
						// this.$u.test.mobile()就是返回true或者false的
						return uni.$u.test.mobile(value);
					},
					message: '手机号码不正确',
					// 触发器可以同时用blur和change
					trigger: ['change', 'blur'],
				}
			],
			services: [{
				required: true,
				message: '请选择陪诊项目',
				// blur和change事件触发检验
				trigger: ['blur', 'change'],
			}, ],
			service_year: [{
				required: true,
				message: '请输入护龄',
				// blur和change事件触发检验
				trigger: ['blur', 'change'],
			}, ],
			address: [{
				required: true,
				message: '请输入地址',
				// blur和change事件触发检验
				trigger: ['blur', 'change'],
			}, ],
			certificate: [{
				required: true,
				message: '请上传资格证书',
				// blur和change事件触发检验
				trigger: ['blur', 'change'],
			}, ],
			report: [{
				required: true,
				message: '请上传体检报告',
				// blur和change事件触发检验
				trigger: ['blur', 'change'],
			}, ],
		}

		let identityList = [{
				img: '/static/img/index/pzs.png',
				name: '陪诊师',
				desc: '为患者提供陪诊服务',
				nav: '/pages/index/selectIdentity/accompany',
				identity: 'master'
			},
			{
				name: '陪诊机构',
				img: '/static/img/index/pzyy.png',
				desc: '为患者提供陪诊服务',
				identity: 'organ',
				nav: '/pages/index/selectIdentity/organization'
			},
			{
				name: '司机',
				img: '/static/img/index/sj.png',
				desc: '为患者提供用车服务',
				identity: 'driver'
			},
		]

		let identity = {
			master: '陪诊师',
			organ: '陪诊机构',
			driver: '司机',
		}

		// 0报价 1抢单 2接单
		let type = {
			0: '报价',
			1: '抢单',
			2: '接单',
		}
		let sex = {
			0: '未知',
			1: '男',
			2: '女',
		}
		let sexImg = {
			0: '未知',
			1: '男',
			2: '女',
		}

		let obj = {
			identityList,
			rules,
			identity,
			type,
			sex
		}

		if (fidle) return obj[fidle] || {}
		return obj
	}
}

export default {
	install
}
